package cn.tedu.controller;

import cn.tedu.entity.User;
import cn.tedu.vo.Result;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

/**
 * 用户controller
 * @author Kiven
 */
@RestController
@RequestMapping("/admin")
@CrossOrigin(origins = "http://localhost:8080", maxAge = 3600)
public class UserController {


    @Value("${server.port}")
    private String port;

    @RequestMapping("/test")
    public String test(){
        return "我是:"+port;
    }

    @RequestMapping("/add")
    public Result<String> addUser(@RequestBody User user){
        System.out.println(user);
        return new Result<String>(false,401,"添加失败");
    }

    @GetMapping
    public List<User> list(User user) {

        List<User> users = new ArrayList<>();

        for (int i = 0; i <10; i++) {

            User build = User.builder().id(1 + i).username("张三" + i).nickname("zhangsan" + i).email("221344" + i + "@qq.com").password("123456" + i).birthday(new Date()).build();
            users.add(build);
        }


        return users;
    }


}
